﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESP
{
    //////////////////////////////////////////////////////////////////////
//   Alan Oursland  
// 
//   ESP Java implementation.
//
//	 This code is a direct port of Faustino Gomez's ESP code
//   that was code started from Daniel Polani's translation of 
//   Dave Moriarty's original SANE code from C to C++.
//   
//   $Log: FeedForwardNetwork.java,v $
//////////////////////////////////////////////////////////////////////////
    public class FeedForwardNetwork : Network
    {
        public FeedForwardNetwork(int inputCount, int neuronCount, int outputCount) :
            base(inputCount, neuronCount, outputCount)
        {
        }

        public override void activate(double[] input, double[] output)
        {
            // evaluate hidden/output layer 
            for (int i = 0; i < getNeuronCount(); ++i)
            {
                //for each hidden unit
                Neuron n = getNeuron(i);

                if (!n.lesioned)
                {
                    activation[i] = 0.0;
                    for (int j = 0; j < getInputCount(); ++j)
                    {
                        activation[i] += n.weight[j]*input[j];
                    }
                    activation[i] = sigmoid(activation[i]);
                }
            }

            for (int i = 0; i < output.Length; ++i)
            {
                output[i] = 0.0;
                for (int j = 0; j < getNeuronCount(); ++j)
                {
                    output[i] += activation[j]*getNeuron(j).weight[getInputCount() + i];
                }
                output[i] = sigmoid(output[i]);
            }
        }

        public override void save(String filename)
        {
            saveText(filename + "_FF");
        }

        public override int getTotalInputs()
        {
            return getInputCount();
        }

        public override int getGeneSize()
        {
            return getInputCount() + getOutputCount();
        }
    }
}
